﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>盘点报告</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>

</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="venCode" placeholder="盘点单号" autocomplete="off" class="layui-input" id="venCode">
                            </div
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="wareName" placeholder="仓库名称" autocomplete="off" class="layui-input" id="wareName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="positionName" placeholder="货位名称" autocomplete="off" class="layui-input" id="positionName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="proCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="proCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                            </div>


                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" id="btn-view" type="button" onclick="loadData()"><i class="layui-icon">&#xe615;</i></button>
                            </div>

                        </form>

                    </div>
                    <div class="layui-card-header">
                            
                                <button class="layui-btn" id="btn-del" type="button" onclick="delReport()"><i class="layui-icon">&#x1007;</i>取消报告</button>
                            
                        </div>
                    <div class="layui-card-body layui-table-body" id="layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>
    var pchCodes = "";
    var isSync = "";
    var pdType = "";//盘点类型

    //var ids = "";
    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
                { type: 'checkbox' }
                , { field: 'venCode', align: 'center', title: '盘点单号', width: '6%' }
                , { field: 'wareName', align: 'center', title: '盘点仓库', width: '6%'  }
                , { field: 'positionName', align: 'center', title: '盘点货位', width: '7%'  }
                , { field: 'proName', align: 'center', title: '存货名称', width: '10%'  }
                , { field: 'spec', align: 'center', title: '规格', width: '6%'  }
                , { field: 'ypNum', align: 'center', title: '物控账面数', width: '6%' , style: "color:blue",event: 'ypDone'}
                , { field: 'ypCount', align: 'center', title: '应盘件数', width: '6%', style: "color:blue",event: 'ypDone'}
                , { field: 'spNum', align: 'center', title: '实盘数', width: '6%', style: "color:blue", event: 'spDone'}
                , { field: 'spCount', align: 'center', title: '实盘件数', width: '6%', style: "color:blue", event: 'spDone' }
                , { field: 'pyNum', align: 'center', title: '盘盈数', width: '6%', style: "color:blue",event: 'pyDone' }
                , { field: 'pyCount', align: 'center', title: '盘盈件数', width: '6%', style: "color:blue", event: 'pyDone' }
                , { field: 'pkNum', align: 'center', title: '盘亏数', width: '6%', style: "color:blue", event: 'pkDone' }
                , { field: 'pkCount', align: 'center', title: '盘亏件数', width: '6%', style: "color:blue",event: 'pkDone' }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
            
            }

            , url: "../ProCheck/GetDataList?dataType=report&condition=" + conditon
            , skin: 'row' //表格风格
             ,loading:true
            , even: true
            , page: true //是否显示分页
            , limits: [20, 30, 50]
            , limit: 15 //每页默认显示的数量
            , id: "tData"
            });

            //监听工具条 多选框
            table.on('checkbox(list)', function (obj) {
                var checkStatus = table.checkStatus('tData');
                pchCodes = ""; isSync = ""; pdType = ""; 
                for (var i = 0; i < checkStatus.data.length; i++) {
                    pchCodes += checkStatus.data[i].pchCode + ",";
                    isSync += checkStatus.data[i].isSync + ",";
                    pdType += checkStatus.data[i].chType + ",";
                }
                pchCodes = pchCodes.substr(0, pchCodes.length - 1);
                isSync = isSync.substr(0, isSync.length - 1);
            });

            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event === 'ypDone') {
                    OpenPage(data.erpCode + "-应盘清单", '../ProCheck/CheckTaskList?dataType=chyp&pchCode=' + data.pchCode);
                } else if (obj.event == 'spDone') {
                    OpenPage(data.erpCode + "-实盘清单", '../ProCheck/TaskRecords?pchCode=' + data.pchCode);
                } else if (obj.event == 'pyDone') {
                    if (userPower.indexOf("pchDochanage") >= 0) {
                        detail(data.pchCode, "Bar", "1", data.erpCode + "-盘盈");
                    } 
                    
                } else if (obj.event == 'pkDone') {
                    if (userPower.indexOf("pchDochanage") >= 0) {
                        detail(data.pchCode, "Bar", "0", data.erpCode + "-盘亏");
                    } 
                }
            });

        });
    }
    function detail(pchCode, barType, ykType, title) {
        var url = '../ProCheck/checkReportResult?barType=' + barType + '&types=' + ykType + '&pchCode=' + pchCode;
        OpenPage(title, url);
    }
    $(function () {
        WebPowersShow();
       // alert(userPower);
        loadData();
    })
 
    /**
取消报告（删除）
**/
    function delReport() {
        if (!isSync.trim(',').includes("1")) {
            if (pchCodes != "") {
                $.ajax({
                    url: "../ProCheck/delReport",
                    data: { pchCodes: pchCodes },
                    dataType: "json",
                    type: "POST",
                    async: false,
                    success: function (data) {
                        if (data.Result) {
                            layer.msg("报告已取消");
                            loadData();
                        } else {
                            layer.msg(data.Message);
                        }
                    }
                });
            }
            else {
                layer.msg("请先选择报告");
            }
        }
        else {
            layer.msg("选中数据存在已同步结果的数据，不允许取消报告！"); return;
        }
    }

</script>